import { MyVue } from 'src/wl/my_vue';
import Vue from 'vue';
import { Component, Emit, Prop, Provide, Watch } from 'vue-property-decorator'
import { WebManageConst } from "src/consts/web_manage_const";
@Component({})
export default class WebMConfigPanel extends MyVue {
    name: string = 'WebMConfigPanel';
    formData: any;
    footerFlag: boolean = true;
    isAdmin: Boolean;
    title: String;
    titleIcon: String;

    beforeCreate(): void {
    }

    initData(that?: any): void {
        var index = WLStore().state.webMShow.ca_index
        var type = WLStore().state.webMShow.login_key

        var user = getUserInfo()
        this.isAdmin = false
        for (let i = 0; i < user.roles.length; i++) {
            if (user.roles[i].id == 1) {
                this.isAdmin = true
            }
        }
        if (WLStore().state.webMShow.ca_type == "edit") {
            that.title = "ca证书信息详情"
            that.titleIcon = "btn_xq"
            that.formData = WLStore().state.webMShow[type + 'CaMsgs'][index];
            if (!this.isAdmin) {
                that.formData.uown_name = user.account
            }
        } else if (WLStore().state.webMShow.ca_type == "add") {
            that.title = "新增ca证书信息"
            that.titleIcon = "pop_xz"
            that.formData = {}
            that.formData.uown_name = user.account
            that.formData.uown_id = user.userId
        }

    }

    mounted(): void {
    }

    uownChange(): void {
        this.formData.uown_id = this.formData.uown_name.id
        this.formData.uown_name = this.formData.uown_name.name
    }

    editCa(): void {
        this.$refs.webMCaForm.validate((valid: Boolean) => {
            if (valid) {
                WLCommit(WebManageConst.CommitCaData, this.formData)
            } else {
                WLMessage("必填字段为空,无法保存ca证书信息", "warning")
                return false;
            }
        })
    }
}